package com.cmdandroid.icebutton;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Contacts.People;
import android.util.Log;

@SuppressWarnings("deprecation")
abstract class ContactsAdapterBridge {
	abstract List<String> getInfo(Activity a, Intent data);
	//abstract String getPhone(Activity a, Intent data);
	//abstract String getEmail(Activity a, Intent data);

	public static final ContactsAdapterBridge INSTANCE=buildBridge();
	public static final Uri URI = getURI();

	private static ContactsAdapterBridge buildBridge() {
		//Get sdk version
		int sdk=new Integer(Build.VERSION.SDK).intValue();

		//If 1.5 or 1.6, implement OldApi
		if (sdk<5) {
			return(new OldContactsAdapterBridge());
		}
		//else, implement NewApi
		return(new NewContactsAdapterBridge());
	}
	
	private static Uri getURI() {
		int sdk=new Integer(Build.VERSION.SDK).intValue();
		Uri CONTENT_URI=null;
		
		//If 1.5 or 1.6, pass OldApi Uri
		if (sdk<5) {
			CONTENT_URI = People.CONTENT_URI;
		}
		//else pass NewApi Uri
		else {
			try {
				Class<?> clazz = Class.forName(
						"android.provider.ContactsContract$Contacts");
				CONTENT_URI = (Uri) clazz.getField("CONTENT_URI").get(clazz);
			}
			catch (Throwable t) {
				Log.e("debug", "Exception when determining CONTENT_URI",t );
			}
		}
		return CONTENT_URI;
	}
}
